<template>
  <div class="login-container">
    <!-- 全屏背景 -->
    <div class="background"></div>

    <!-- 登录表单 -->
    <div class="login-form-container">
      <div class="cbj"></div>
      <el-row type="flex" align="middle" class="full-height">
        <div class="login-form-card">
          <el-form
            ref="loginForm"
            :model="formModel"
            :rules="rules"
            class="biaodan"
            label-position="left"
          >
            <el-form-item>
              <h3 class="title">欢迎使用</h3>
            </el-form-item>
            <el-form-item>
              <h2 style="margin-left: 20px">后台管理</h2>
            </el-form-item>
            <el-form-item prop="username">
              <el-input v-model="formModel.username" placeholder="用户名"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                v-model="formModel.password"
                type="password"
                placeholder="密码"
                show-password
              ></el-input>
            </el-form-item>
            <el-form-item prop="isrray">
              <el-checkbox v-model="formModel.isrray">同意使用服务条约</el-checkbox>
            </el-form-item>
            <el-form-item>
              <el-button @click="login" type="primary" style="width: 100%"> 登录 </el-button>
            </el-form-item>
            <el-form-item>
              <el-button style="width: 100%"> 重置 </el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import router from '@/router'
import { ref } from 'vue'

const loginForm = ref()
const formModel = ref({
  username: '',
  password: '',
  isrray: false,
})
const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 5, max: 10, message: '用户名必须是 5-10位 的字符', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
    {
      pattern: /^\S{6,15}$/,
      message: '密码必须是 6-15位 的非空字符',
      trigger: 'blur',
    },
  ],
  isrray: [
    {
      validator: (rule, value, callback) => {
        if (!value) {
          callback(new Error('请同意勾选协议'))
        } else {
          callback()
        }
      },
      trigger: 'blur',
    },
  ],
}

const login = async () => {
  await loginForm.value.validate()
  router.push('/peijian')
  formModel.value = {}
}
</script>

<style scoped>
.cbj {
  position: absolute;
  top: 180px;
  left: 400px;
  height: 443px;
  width: 300px;
  background-image: url(src/assets/che-b8b6cbcc.png);
  background-size: cover;
}
.login-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: -1; /* 确保背景在内容下方 */
}
.background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-image: url(src/assets/bg-09ca65c0.png); /* 替换为你的背景图URL */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: -1;
}
.login-form-container {
  position: relative;
  height: 100vh;
}

.full-height {
  height: 100%;
}

.login-form-card {
  background-color: rgba(255, 255, 255, 0.9); /* 半透明背景 */
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  text-align: center;
  height: 440px;
  width: 230px;
  position: absolute;
  left: 700px;
  top: 180px;
}

.title {
  color: #333;
  margin-bottom: 0px;
}
</style>
